package com.gin.no_gay_alliance.viewmodel;

import com.gin.jackson.utils.ObjectUtils;
import com.gin.nga.enums.SubForumType;
import com.gin.nga.response.field.FavorForum;
import com.gin.nga.response.forum.ForumEntry;

/**
 * 版面/合集入口数据
 */
public class EntryData {
    /**
     * 版面/合集 id
     */
    public long id;
    /**
     * 版面/合集 名称
     */
    public String name;
    /**
     * 版面图标地址
     */
    public String icon;
    /**
     * 类型：版面或合集
     */
    public SubForumType type;

    public EntryData(ForumEntry forumEntry) {
        if (forumEntry.getColTid() != null) {
            this.id = forumEntry.getColTid();
            this.type = SubForumType.COL;
        } else {
            this.id = forumEntry.getForumId();
            this.type = SubForumType.FORUM;
        }

        this.icon = forumEntry.getBigIconUrl();

        if (!ObjectUtils.isEmpty(forumEntry.getName())) {
            this.name = forumEntry.getName();
        } else if (!ObjectUtils.isEmpty(forumEntry.getSimpleName())) {
            this.name = forumEntry.getSimpleName();
        }
    }

    public EntryData() {
    }

    public EntryData(FavorForum favorForum) {
        if (favorForum.getColTid() != null) {
            this.id = favorForum.getColTid();
            this.type = SubForumType.COL;
        } else {
            this.id = favorForum.getForumId();
            this.type = SubForumType.FORUM;
        }
        this.icon = favorForum.getBigIconUrl();
        this.name = favorForum.getName();
    }
}